package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Personnel;
import com.haoan.index.service.PersonnelService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 企业人员Controller
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Api(value="企业人员",tags = "企业人员")
@RestController
@RequestMapping("/index/personnel")
public class PersonnelController extends BaseController
{
    @Resource
    private PersonnelService personnelService;

    /**
     * 查询企业人员列表
     */
    @ApiOperation("查询企业人员列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Personnel personnel)
    {
        startPage();
        List<Personnel> list = personnelService.selectPersonnelList(personnel);
        return getDataTable(list);
    }

    /**
     * 导出企业人员列表
     */
    @ApiOperation("导出企业人员列表")
    @PreAuthorize("@ss.hasPermi('index:personnel:export')")
    @Log(title = "企业人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Personnel personnel)
    {
        List<Personnel> list = personnelService.selectPersonnelList(personnel);
        ExcelUtil<Personnel> util = new ExcelUtil<Personnel>(Personnel.class);
        util.exportExcel(response, list, "企业人员数据");
    }

    /**
     * 获取企业人员详细信息
     */
    @ApiOperation("获取企业人员详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(personnelService.selectPersonnelById(id));
    }

    /**
     * 新增企业人员
     */
    @ApiOperation("新增企业人员")
    @PreAuthorize("@ss.hasPermi('index:personnel:add')")
    @Log(title = "企业人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Personnel personnel)
    {
        return toAjax(personnelService.insertPersonnel(personnel));
    }

    /**
     * 修改企业人员
     */
    @ApiOperation("修改企业人员")
    @PreAuthorize("@ss.hasPermi('index:personnel:edit')")
    @Log(title = "企业人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Personnel personnel)
    {
        return toAjax(personnelService.updatePersonnel(personnel));
    }

    /**
     * 删除企业人员
     */
    @ApiOperation("删除企业人员")
    @PreAuthorize("@ss.hasPermi('index:personnel:remove')")
    @Log(title = "企业人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(personnelService.deletePersonnelByIds(ids));
    }
}
